<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box1,#box2 {
            width: 300px;
            height: 300px;
            border: 1px solid black;
            float: left;
            margin: 20px;
            /* 方式一：使用网格布局 */
            /* display: grid;   */
            /* 方式二：使用弹性布局 */
            /* display: flex; */
            /* 方式三：使用定位 */

            /* 方式四：使用位移 */
            position: relative;  
        }
        .box1-1,.box2-1 {
            /* margin: auto; */

            /* position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%); */

            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
        }
        .box1-1 {
            background: lightblue;
            width: 100px;
            height: 100px;
        }
        .box2-1 {
            background: lightpink;
            width: 150px;
            height: 200px;
        }
    </style>
</head>
<body>
    <div id="box1">
        <div class="box1-1"></div>
    </div>
    <div id="box2">
        <div class="box2-1"></div>
    </div>
</body>
</html>